package com.cdcas;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/login")
public class login extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uname = req.getParameter("u1");
        String upassword = req.getParameter("p1");
        System.out.println("从jsp传递的用户名：" + uname + " 密码：" + upassword);
        if (uname !=null && uname.length()>0 && upassword!=null && upassword.length()>0) {
            //查询数据库 是否有用户名和密码记录
            //如果查询到记录，则调转至main.jsp

            //页面之间跳转
            resp.sendRedirect("main.jsp");


        }else {
            resp.sendRedirect("index.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
